import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import RandomUtil from '@/RandomUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import RandomCommon from 'code/Core/Common/RandomCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 剧毒之刃
 **/
export default class DZ_PoisionKnive extends AbilityBase {
    static instance: DZ_PoisionKnive;
    buffType: AppBuffType = {
        id: 'buff_DZ_PoisionKnive',
        art: this.art,
        name: this.abilityName,
        ubertip: '在攻击敌人时有机率使敌人中毒，持续造成与攻击相关的毒性伤害',
    };
    debuffType: AppBuffType = {
        id: 'buff_DZ_PoisionKnive_debuff',
        art: this.art,
        name: this.abilityName,
        ubertip: '受到剧毒之刃的影响，持续受到毒性伤害,并且降低了攻击速度与生命回复速度',
        isDebuff: true,
        dur: 4,
        stackCountMax: 10,
        targetAttach: 'origin',
        targetArt: 'Abilities\\Weapons\\PoisonSting\\PoisonStingTarget.mdl',
        attribute: {
            attackSpd_p: -0.05,
            生命恢复增强: -0.05,
        },
        onInterval: this.buffInterval.bind(this),
        interval: 1,
    };
    buffInterval(buff: Buff) {
        let lv = this.getAbilityLevel(buff.getCaster());
        let dmg = UnitCommon.取攻击(buff.getCaster()) * 0.14 * lv + UnitCommon.取法强(buff.getCaster()) * 0.35 * lv;
        DamageSystemInstance.applyPoisionDamage(buff.getParent(), buff.getCaster(), dmg * buff.stackCount, this.id, true);
        DestroyEffect(AddSpecialEffectTarget('Objects\\Spawnmodels\\Demon\\DemonBlood\\DemonBloodPitlord.mdl', buff.getParent(), 'origin'));
    }
    constructor(id: string = 'Ajdr') {
        super(id);
        DZ_PoisionKnive.instance = this;
        this.init();
        this.onLevelChange(this.onLevelChangeEffect.bind(this));
        this.onRemove(this.onLevelChangeEffect.bind(this));
        EventManager.onTakeAttack(this.onAttackEffect.bind(this));
    }
    onLevelChangeEffect(p: { unit: unit; ability: DZ_PoisionKnive }) {
        let lv = this.getAbilityLevel(p.unit);
        BuffCommon.addBuff({ target: p.unit, caster: p.unit, buffTypeId: this.buffType.id, ablityId: this.id, config: { stack: lv } });
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
        BuffUtil.registerBuffType(this.debuffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // BuffUtil.addBuff(target, this.buffType.id, source);
        BuffCommon.addBuff({ target, caster: source, buffTypeId: this.buffType.id, ablityId: this.id });
    }
    onAttackEffect(d: DamageEventData) {
        if (!BuffUtil.hasUnitBuff(d.source, this.buffType.id)) return;
        let r = RandomUtil.randomPercent();
        let max = RandomCommon.getSkillRate(0.25, d.source, this.id);
        if (r > max) return;
        this.cast(0, 0, d.source, d.target);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
